package spindles.api.util;

import java.io.BufferedReader;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.ArrayUtils;

import spindles.api.util.Config;
import spindles.api.util.FileUtil;
import spindles.api.util.Processor;

import junit.framework.TestCase;

public class BaseTestCase extends TestCase {

	public static final String baseDir = "G:\\Projects\\spindles";

	public BaseTestCase(String arg0) {
		super(arg0);
		init();
	}

	protected void setUp() throws Exception {
		super.setUp();
	}

	protected void tearDown() throws Exception {
		super.tearDown();
	}
	
	public static void init(){
		Config.testInit(BaseTestCase.baseDir);
	}
	
	public static double[] toArray(String fileName){
		File f = new File(fileName);
		try {
			final List<Double> result = new ArrayList<Double>();
			FileUtil.readFile(f, new Processor() {

				public void process(BufferedReader r) throws Exception {
					String line;
					while ((line = r.readLine()) != null) {
						result.add(new Double(line.trim()));
					}
				}

			});
			return ArrayUtils.toPrimitive(result.toArray(new Double[0]));
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

}
